package org.bedracket.bedracketenchantment.enchantment;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;

import java.util.Random;

public class RandomizationEnchantment extends Enchantment {
    public RandomizationEnchantment() {
        super(Rarity.VERY_RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
    }

    @Override
    public int getMinCost(int level) {
        return 12;
    }

    @Override
    public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) {
        if (pTarget instanceof final LivingEntity living) {
            Random random = living.getRandom();
            BlockPos.MutableBlockPos blockpos$mutableblockpos = living.getOnPos().mutable();
            living.randomTeleport(blockpos$mutableblockpos.getX() + random.nextInt(11) - 5,
                            blockpos$mutableblockpos.getY() + random.nextInt(5) - 2,
                            blockpos$mutableblockpos.getZ() + random.nextInt(11) - 5,
                            false);
        }
    }
}
